﻿using System;
using System.ComponentModel.Design;
using System.Resources;
using System.IO;

namespace SedionFormDesigner.Service
{
    /// <summary>
    ///  根据指定CulctureInfo资源设置序列化和反序列化
    /// </summary>
    public class SedionResourceService : IResourceService
    {
        private IDesignerHost host;
        private ResourceReader reader;
        private ResourceWriter writer;
        private MemoryStream memoryStream;

        public SedionResourceService(IDesignerHost host)
        {
            this.host = host;
        }

        #region IResourceService 成员

        public System.Resources.IResourceReader GetResourceReader(System.Globalization.CultureInfo info)
        {
            if (reader == null)
            {
                if (memoryStream == null)
                    memoryStream = new MemoryStream();
                reader = new ResourceReader(memoryStream);
            }
            return reader;
        }

        public System.Resources.IResourceWriter GetResourceWriter(System.Globalization.CultureInfo info)
        {
            if (writer == null)
            {
                if (memoryStream == null)
                    memoryStream = new MemoryStream();
                writer = new ResourceWriter(memoryStream);
            }
            return writer;
        }

        #endregion
    }
}
